from rest_framework import serializers
from cms import models
class CMS_STUDENT_serializer(serializers.ModelSerializer):

    ''' 可以取到当前表 以及多找一类型的附属表所有内容 '''

    sec_user = serializers.CharField(source='STUDENT_ID')
    sec_class = serializers.CharField(source='STUDENT_ID.CLASS_ID.CLASS_NUM')
    sec_grade = serializers.CharField(source='STUDENT_ID.CLASS_ID.GREAD_ID.GREAD_NUM')
    sec_scoreinfo = serializers.CharField(source='SCORESTYLE_ID.ADD_SCORE_STYLE')
    class Meta:
        model = models.CMS_SCORE
        fields = '__all__'
        # fields = ['ID','SCORE','UPDATED_TIME','sec_user','sec_class','sec_grade','sec_scoreinfo']
        # extra_kwargs = {'STUDENT_ID': {'source': 'get_USERNAME_display'},}
        depth = 5


class CMS_COLLEGE_serializer(serializers.ModelSerializer):
    # 逆向查询需要在forigenKEY键上,设置related_name='college_org'属性,可以从一表查多表内容

    # college_org = serializers.PrimaryKeyRelatedField(many=True, required=False, read_only=True)
    class Meta:
        model = models.CMS_STUDENT
        fields = '__all__'
        # fields = ['ID','COLLEGE_NAME','CREATED_TIME','college_org',]

        depth = 5
